/**
 * Created by joy on 12/09/2017.
 */
import EthRpcHelper from '../../common/helpers/chain/EthRpcHelper'
import EthWalletHelper from '../../common/helpers/chain/EthWalletHelper'
import CommonUtil from '../../common/utils/CommonUtil'
import prompt from 'prompt'


export default async () => {
  const schema = {
    properties: {
      host: {
        description: 'Enter host of node',
        type: 'string',
        required: true,
        default: '127.0.0.1'
      },
      port: {
        description: 'Enter port of node',
        type: 'number',
        required: true,
        default: 8545
      },
      privateKey: {
        description: 'Enter privateKey',
        type: 'string',
        required: true,
        default: '0x6b406fa165e1507ffc49f9b53914fb1d6871c310d6488653d40ce5016c0eed1c'
      },
      amount: {
        description: 'Enter amount',
        type: 'number',
        required: true,
        default: 0.1
      },
      toAddress: {
        description: 'Enter toAddress',
        type: 'string',
        required: true,
        default: '0x00367f9370A71Cf482A64394dFB2367aa3a34339'
      }
    }
  }

  const args = await CommonUtil.getArgsFromConsole(prompt, schema)
  let { host, port, privateKey, amount, toAddress } = args
  const ethRpcHelper = new EthRpcHelper(host, port), ethWalletHelper = new EthWalletHelper()
  const txHex = ethWalletHelper.buildTransaction(ethRpcHelper, privateKey, toAddress, amount)
  logger.info('txHex', txHex)

  const hash = await ethRpcHelper.sendRawTransaction(txHex)
  logger.info('hash', hash)
}
